#include <iostream>
#include <limits.h>

using namespace std;
/**
 * @brief
 * 1 <= num <= 2^31 - 1
 *  Follow up: Do not use any built-in library function such as sqrt.
 */
class Solution
{
public:
    /**
     * @brief
     * 2000105819
     *
     * @param num
     * @return true
     * @return false
     */
    bool isPerfectSquare(int num)
    {
        if (num == 1)
        {
            return true;
        }
        int left = 0, right = num / 2;
        while (left <= right)
        {
            long mid = left + (right - left) / 2;

            if (mid * mid == num)
            {
                return true;
            }
            else if (mid * mid < num)
            {
                left = mid + 1;
            }
            else
            {
                right = mid - 1;
            }
        }
        return false;
    }
};
int main()
{
    Solution s;
    cout << s.isPerfectSquare(1) << endl;
    return 0;
}
